Jan-Philipp Kolb
23 Juni 2017
ggplot2ggplot2<www.r-bloggers.com/basic-introduction-to-ggplot2/>
install.packages("ggplot2")library(ggplot2)diamonds Datensatzhead(diamonds)| carat | cut | color | clarity | depth | table | price | x | y | z |
|---|---|---|---|---|---|---|---|---|---|
| 0.23 | Ideal | E | SI2 | 61.5 | 55 | 326 | 3.95 | 3.98 | 2.43 |
| 0.21 | Premium | E | SI1 | 59.8 | 61 | 326 | 3.89 | 3.84 | 2.31 |
| 0.23 | Good | E | VS1 | 56.9 | 65 | 327 | 4.05 | 4.07 | 2.31 |
| 0.29 | Premium | I | VS2 | 62.4 | 58 | 334 | 4.20 | 4.23 | 2.63 |
| 0.31 | Good | J | SI2 | 63.3 | 58 | 335 | 4.34 | 4.35 | 2.75 |
| 0.24 | Very Good | J | VVS2 | 62.8 | 57 | 336 | 3.94 | 3.96 | 2.48 |
qplotqplot wird für schnelle Graphiken verwendet (quick plots)ggplot kann man alles bis ins Detail kontrollieren# histogram
qplot(depth, data=diamonds)qplot(cut, depth, data=diamonds)qplot(factor(cyl), data=mtcars,geom="bar")qplot(data=diamonds,x=cut,y=depth,geom="boxplot")# scatterplot
qplot(carat, depth, data=diamonds)qplot(carat, depth, data=diamonds,color=cut)myGG<-qplot(data=diamonds,x=carat,y=depth,color=carat)
myGG + stat_smooth(method="lm")qplot(factor(cyl), data=mtcars, geom="bar") +
coord_flip()ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar()Es wird das Paket RColorBrewer verwendet um die Farbpalette zu ändern
install.packages("RColorBrewer")library(RColorBrewer)
myColors <- brewer.pal(5,"Accent")
names(myColors) <- levels(diamonds$cut)
colScale <- scale_colour_manual(name = "cut",
values = myColors)p <- ggplot(diamonds,aes(carat, depth,colour = cut)) +
geom_point()
p + colScaleggsave("Graphik.jpg")Arten von räumlichen Daten:
Das R-paket ggmap wird im folgenden genutzt um verschiedene Kartentypen darzustellen.
Mit qmap kann man eine schnelle Karte erzeugen.
ggmap:devtools::install_github("dkahle/ggmap")
devtools::install_github("hadley/ggplot2")
install.packages("ggmap")librarylibrary(ggmap)Und schon kann die erste Karte erstellt werden:
qmap("Mannheim")BBT <- qmap("Berlin Brandenburger Tor")
BBTqmap("Germany")qmap("Germany", zoom = 6)